﻿using GalleryDataProvider;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using GalleryCommon;

namespace GalleryLogic
{
    public static class UserLogic
    {
        private static readonly MD5 md5 = new MD5CryptoServiceProvider();

        public static bool AddNewUser(string email, string userName, string password)
        {
            

            byte[] data = Encoding.UTF8.GetBytes(password);
            byte[] securePassword = md5.ComputeHash(data);
            return UserDataProvider.AddNewUser(email, userName, securePassword);
        }

        public static bool UserLogin(string email, string password, out User user)
        {
            byte[] data = Encoding.UTF8.GetBytes(password);
            byte[] securepassword;
            securepassword = md5.ComputeHash(data);

            return GalleryDataProvider.UserDataProvider.CheckUser(email, securepassword, out user);
        }
    }
}
